/*****************************************************************************/
/*                Perot Systems Framework                                    */
/*****************************************************************************/
/* Stored Procedure :: ApplicationShutdown()                                 */
/* Registers Shutdown event for an application                               */
/*****************************************************************************/
/* Copyright (C) 2003-2004, Perot Systems Corporation. All right reserved.   */
/* Developer: Dima Frenkel (dima.frenkel@ps.net)                             */
/* Started:  08/04/2004                                                      */
/*****************************************************************************/
/* Modifications                                                             */
/* Date       |  Author          | Description                               */
/*------------+------------------+-------------------------------------------*/
/*            |                  |                                           */
/*****************************************************************************/

/******************************************************************************/
/* Step 0. Preparations/Declarations                                          */
/******************************************************************************/
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

/******************************************************************************/
/* Step 1. Remove stored procedure if it already exists                       */
/******************************************************************************/
IF (SELECT OBJECT_ID('[Kernel].[ApplicationShutdown]')) IS NOT NULL BEGIN
  DROP PROCEDURE [Kernel].[ApplicationShutdown] END

GO

/*****************************************************************************/
/* Stored Procedure :: ApplicationShutdown                                   */
/*****************************************************************************/
/* Copyright (C) 2003-2004, Perot Systems Corporation. All right reserved.   */
/* Developer: Dima Frenkel (dima.frenkel@ps.net)                             */
/* Started:  08/04/2004                                                      */
/*****************************************************************************/
CREATE PROCEDURE [Kernel].[ApplicationShutdown]( 
	@OID BIGINT,
	@FinishTime datetime = null
)
AS 
BEGIN
  SET @FinishTime = ISNULL( @FinishTime, GETDATE() )
  
  UPDATE ApplicationLog
     SET FinishTime = @FinishTime
   WHERE OID = @OID AND FinishTime IS NULL
END
GO

/******************************************************************************/
/* Step 3. Assign appropriate permissions                                     */
/******************************************************************************/
GRANT EXECUTE ON [DBO].[ApplicationShutdown] TO [Liberty_Users]
GO
-- Developers and Admins have permissions to execute through membership   
